home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BEERSRC.ZIP / CONVERT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-24  |  3.0 KB  |  160 lines

  1.  
  2. #include <io.h>
  3. #include <fcntl.h>
  4. #include <sys\stat.h>
  5. #include <dos.h>
  6. #include <stdio.h>
  7. #include <conio.h>
  8. #include <string.h>
  9. #include <alloc.h>
  10.  
  11.  
  12. char palette[768];
  13.  
  14.  
  15. void loadpic(char *file)
  16. {
  17.    int      filvar;
  18.    char     data, count;
  19.    unsigned pos, i;
  20.  
  21.  
  22.    filvar = open(file, O_RDONLY | O_BINARY, S_IREAD);
  23.    lseek(filvar, -768, SEEK_END);
  24.    read(filvar, palette, 768);
  25.    for (i = 0; i < 768; i++) {
  26.       palette[i] /= 4;
  27.    }
  28.  
  29.    lseek(filvar, 128, SEEK_SET);
  30.  
  31.    pos = 0;
  32.    while ((read(filvar, &count, 1) == 1) && (pos < 0xfa00)) {
  33.       if ((count & 0xc0) == 0xc0) {
  34.      count = count & 0x3f;
  35.      read(filvar, &data, 1);
  36.       } else {
  37.      data = count; count = 1;
  38.       }
  39.  
  40.       for (i = 0; i < count; i++) {
  41.      pokeb(0xa000, pos++, data);
  42.       }
  43.    }
  44.  
  45.    close(filvar);
  46.  
  47.  
  48. }
  49.  
  50.  
  51. void screenmode(int mode)
  52. {
  53.    struct REGPACK regs;
  54.  
  55.    regs.r_ax = mode;
  56.    intr(0x10, ®s);
  57.  
  58.    regs.r_ax = 0x0100;
  59.    regs.r_cx = 0x2000;
  60.    intr(0x10, ®s);
  61.  
  62. }
  63.  
  64. void setcolor(char *ptr)
  65. {
  66.    struct REGPACK regs;
  67.  
  68.    regs.r_ax = 0x1012;
  69.    regs.r_bx = 0;
  70.    regs.r_cx = 256;
  71.    regs.r_dx = (unsigned) ptr;
  72.    regs.r_es = _DS;
  73.    intr(0x10, ®s);
  74.  
  75. }
  76.  
  77. void setattrib(int m)
  78. {
  79.    struct REGPACK regs;
  80.  
  81.    regs.r_ax = 0x1013;
  82.    regs.r_bx = (m << 8);
  83.    intr(0x10, ®s);
  84.  
  85. }
  86.  
  87.  
  88. void main(void)
  89. {
  90.    int  filvar;
  91.    int  x, y, k, p;
  92.    char file[80];
  93.    int  size, ptr;
  94.    int  xs, ys, n, lines;
  95.    int  *mem;
  96.  
  97.  
  98.    directvideo = 0;
  99.  
  100.    printf("\n\n\n\nSprite Converter ver 2.0 [c] by Alpha-Helix 1991.\n\n");
  101.    printf("Enter name of a 320x200 256 color PCX file [.PCX]: ");
  102.    scanf("%s", file); strcat(file, ".PCX");
  103.  
  104.    screenmode(0x13);
  105.  
  106.    setattrib(1);
  107.    loadpic(file);
  108.    setcolor(palette);
  109.  
  110.    gotoxy(1, 24); printf("                         ");
  111.    gotoxy(1, 24); printf("x-size: ");
  112.    scanf("%d", &xs);
  113.    gotoxy(1, 24); printf("                         ");
  114.    gotoxy(1, 24); printf("y-size: ");
  115.    scanf("%d", &ys);
  116.    gotoxy(1, 24); printf("                         ");
  117.    gotoxy(1, 24); printf("n of lines: ");
  118.    scanf("%d", &lines);
  119.    gotoxy(1, 24); printf("                         ");
  120.    gotoxy(1, 24); printf("total n of pics: ");
  121.    scanf("%d", &n);
  122.    gotoxy(1, 24); printf("                         ");
  123.    gotoxy(1, 24); printf("output [.SPR]: ");
  124.    scanf("%s", file); strcat(file, ".SPR");
  125.  
  126.  
  127.    size = xs * ys * n;
  128.    mem = (int *) malloc(size + 6);
  129.  
  130.    ptr = 0;
  131.    mem[ptr++] = xs;
  132.    mem[ptr++] = ys;
  133.    mem[ptr++] = n;
  134.  
  135.    for (p = 0; p < lines; p++) {
  136.       gotoxy(1, 24); printf("                         ");
  137.       gotoxy(1, 24); printf("n of pics on line %d: ", p);
  138.       scanf("%d", &n);
  139.       for (k = 0; k < n; k++) {
  140.  
  141.      for (y = 0; y < ys; y++) {
  142.         for (x = 0; x < xs / 2; x++) {
  143.  
  144.            mem[ptr++] = peek(0xa000, k*xs + y*320 + x*2 + p*ys*320);
  145.  
  146.         }
  147.      }
  148.       }
  149.    }
  150.  
  151.  
  152.    filvar = open(file, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IWRITE);
  153.    write(filvar, mem, size+6);
  154.    close(filvar);
  155.  
  156.    screenmode(2);
  157.  
  158.  
  159. }
  160.